package com.cryptoneedle.center.source.entity.constraint;


import cn.hutool.v7.core.bean.BeanUtil;
import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.center.source.key.constraint.ConstraintColumnKey;
import com.cryptoneedle.center.source.key.metadata.ColumnKey;
import com.cryptoneedle.center.source.key.metadata.DatabaseKey;
import com.cryptoneedle.center.source.key.metadata.TableKey;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
 * <p>description: 源数据源-主键约束 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-20
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
@jakarta.persistence.Table(schema = "public", name = "source_constraint_primary")
@IdClass(ConstraintColumnKey.class)
@Comment("源数据源-主键约束")
public class ConstraintPrimary extends BaseEntity {

    @Id
    @Comment("源数据源-目录名称")
    private String catalogName;
    @Id
    @Comment("源数据源-数据库名称")
    private String databaseName;
    @Id
    @Comment("源数据源-表名称")
    private String tableName;
    @Id
    @Comment("源数据源-约束名称")
    private String constraintName;
    @Id
    @Comment("源数据源-列名称")
    private String columnName;

    @Comment("源数据源-排序")
    private Integer position;

    /**
     * Key
     */

    public ConstraintColumnKey constraintPrimaryKey() {
        return BeanUtil.copyProperties(this, ConstraintColumnKey.class);
    }

    public DatabaseKey databaseKey() {
        return BeanUtil.copyProperties(this, DatabaseKey.class);
    }

    public TableKey tableKey() {
        return BeanUtil.copyProperties(this, TableKey.class);
    }

    public ColumnKey columnKey() {
        return BeanUtil.copyProperties(this, ColumnKey.class);
    }
}
